package cn.bluemobi.dylan.step.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Toast;


import javax.inject.Inject;

import cn.bluemobi.dylan.step.app.App;
import cn.bluemobi.dylan.step.di.component.ActivityComponent;
import cn.bluemobi.dylan.step.di.component.DaggerActivityComponent;
import cn.bluemobi.dylan.step.di.module.ActivityModule;

public abstract class BaseMvpActivity<T extends BasePresenter> extends BaseActivity implements BaseView {
    @Inject
    protected T mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        initInject(); //实例化presenter对象
        if (mPresenter != null)
            mPresenter.attachView(this);
        super.onCreate(savedInstanceState);
    }

    protected ActivityComponent getActivityComponent() {
        return DaggerActivityComponent.builder()
                .appComponent(App.getAppComponent())
                .activityModule(getActivityModule())
                .build();
    }

    protected ActivityModule getActivityModule() {
        return new ActivityModule(this);
    }

    protected abstract void initInject();

    @Override
    public void showError(String msg) {
        Toast.makeText(this,msg,Toast.LENGTH_LONG).show();
    }

    @Override
    public void stateError() {

    }
}
